//- Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd. 
//- <https://www.chatopera.com>, Licensed under the Chunsong Public 
//- License, Version 1.0  (the "License"), https://docs.cskefu.com/licenses/v1.html
//- Unless required by applicable law or agreed to in writing, software
//- distributed under the License is distributed on an "AS IS" BASIS,
//- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//- See the License for the specific language governing permissions and
//- limitations under the License.
//- Copyright (C) 2018-Jun. 2023 Chatopera Inc, <https://www.chatopera.com>
//- Licensed under the Apache License, Version 2.0
//- http://www.apache.org/licenses/LICENSE-2.0
link(rel='stylesheet', type='text/css', href='/js/scrawl/css/scrawl.css')
script(type='text/javascript', src='/js/scrawl/scrawl.js')
script(language='javascript').
    var msgid = "#{chatMessage.id}", fileid = "#{chatMessage.attachmentid}";
    var height;
    var width;
    $(document).ready(function () {
        height = $('#ukefu-image-content')[0].offsetHeight;
        width = $('#ukefu-image-content')[0].offsetWidth;
        $('#ukefu-image-content')[0].width = width;
        if('#{agentUser}' && !'#{t}'){
            top.layer.confirm(
                "访客在线，是否邀请协作对话？",
                {
                    btn: ['邀请', '不邀请'] //按钮
                },
                function (index) {
                    layer.close(index);
                    top.WebIM.sendTypeMessage("${chatMessage.id!''}", "${user.id!''}", "${agentUser.appid!''}", "${user.sessionid!''}", "<#if agentUser??>${agentUser.userid!''}</#if>", "${user.username!''}", "cooperation", "${chatMessage.attachmentid!''}");
                },
                function (index) {
                    layer.close(index);
                }
            );
        }
        $("#ukefu_img_ctx").load(function () {

            console.log($('#ukefu-image-content')[0].offsetHeight);
            new Canvas({
                canvasId: "canvas-borad",
                width: width,
                height: height
            });
            var canvas = $("#canvas-borad")[0];
            if (canvas.getContext) {
                //获取对应的CanvasRenderingContext2D对象(画笔)
                var ctx = canvas.getContext("2d");

                //创建新的图片对象
                var img = new Image();
                //指定图片的URL
                img.src = "/res/image.html?id=${chatMessage.attachmentid!''}&cooperation=true&original=true";
                //浏览器加载图片完毕后再绘制图片
                img.onload = function () {
                    //以Canvas画布上的坐标(10,10)为起始点，绘制图像
                    ctx.drawImage(img, 0, 0);
                };
            }
        });
    });
.ukefu-preview-image.scrawl-main#scrawl-main
    .ukefu-image-content.hot(style='max-width: none;width: 100%')
        .ukefu-image-canvas#ukefu-image-content
            img#ukefu_img_ctx(src=chatMessage.message)
        .drawBoard
            canvas#canvas-borad.brushBorad 你的浏览器不支持 canvas 绘图
